package org.urey.fmp.consumer.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.urey.fmp.consumer.processor.CustomRequestBodyParameterProcessor;
import org.urey.fmp.consumer.processor.MapGenericHttpMessageConverter;

import com.fasterxml.jackson.databind.ObjectMapper;

import feign.Contract;

@Configuration
public class FeignSupportConfig {
	
	@Autowired
	private ObjectMapper objectMapper;

	@Autowired
	private CustomRequestBodyParameterProcessor customRequestBodyParameterProcessor;

	@Bean
	public Contract feignContract() {
		List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();
		annotatedArgumentResolvers.add(customRequestBodyParameterProcessor);
		return new SpringMvcContract(annotatedArgumentResolvers);
	}
	
	@Bean
	public MapGenericHttpMessageConverter mapGenericHttpMessageConverter() {
		return new MapGenericHttpMessageConverter(objectMapper);
	}

}
